﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Web.UI;
using DevExpress.Web.ASPxHeadline;
using DevExpress.Web.ASPxClasses;
using DevExpress.Web.ASPxCallback;

using LMD.Constant;
using LMD.Lib.DataClass;
using LMD.Lib.Interface;
using LMD.Lib.Oracle;
using LMD.Lib.Controls;

public partial class CDReport : ICPRelationshipPage
{
    public DataTable m_dtReport;
    public DataTable m_dtReportCAR;
    public String m_sxType;
    public String m_sxClass;
    #region Properties
    public String m_sxMode
    {
        get
        {
            if (!String.IsNullOrEmpty(Request.QueryString["mode"]))
            {
                return Request.QueryString["mode"];
            }
            else
            {
                return String.Empty;
            }
        }
    }
    #endregion Properties

    #region Event Handlers

    protected override void Page_Load(object sender, EventArgs e)
    {
        m_lsPermittedRoles.Add(ICPUserRole.CAR);
        base.Page_Load(sender, e);

        Page.Title = "ICP Lintasarta: Relationship, Config & Datek - Report";
        if (!IsPostBack && !IsCallback)
        {
            
        }
        if (String.IsNullOrEmpty(m_sxMode))
        {
            InitReportByClass();
            InitReportByCAR();
        }
        else
        {
            InitReportByMode();
        }
    }
    
    #endregion Event Handlers

    #region Custom Methods
    protected override void DoSearch(String sxSearchQuery)
    {
        throw new NotImplementedException();
    }
    protected void InitReportByClass()
    {
        Cached.KonfigurasiDatekTable cachedKonfigDatek = new Cached.KonfigurasiDatekTable();
        m_dtReport = cachedKonfigDatek.LoadCDReport();
        m_dtReportCAR = cachedKonfigDatek.LoadCDReportCAR();
    }
    protected void InitReportByCAR()
    {
        Cached.KonfigurasiDatekTable cachedKonfigDatek = new Cached.KonfigurasiDatekTable();
        m_dtReportCAR = cachedKonfigDatek.LoadCDReportCAR();

        dgReportByCAR.DataSource = m_dtReportCAR;
        dgReportByCAR.DataBind(); 
    }
    protected void InitReportByMode()
    {
        m_sxClass = m_sxMode.Split('_')[0].ToUpper();
        m_sxType = m_sxMode.Split('_')[1].ToUpper();
        Cached.KonfigurasiDatekTable cachedKonfigDatek = new Cached.KonfigurasiDatekTable();
        DataTable dtReportMode = cachedKonfigDatek.LoadCDReportMode(m_sxClass, m_sxType);

        dgReportByMode.DataSource = dtReportMode;
        dgReportByMode.DataBind();
        dgReportByMode.Columns["CUSTOMER_ID"].Visible = false;
    }
    #endregion Custom Methods
}
